[tox]
skipsdist = true
envlist = py{38,39,310,311,312}, dist, manifest, docs, binder

[gh-actions]
python =
    3.8: py38
    3.9: py39
    3.10: py310
    3.11: py311, docs
    3.12: py312, dist

# Manifest
[testenv:manifest]
skip_install = true
deps = check-manifest
commands = check-manifest
ignore =
    .readthedocs.yaml

# Docs
[testenv:docs]
description = invoke sphinx-build to build the HTML docs
deps =
    .[docs]
extras = docs
commands =
    sphinx-build -d "{toxworkdir}/docs_doctree" docs "{toxworkdir}/docs_out" --color -W -bhtml {posargs}
    python -c 'import pathlib; print("documentation available under file://\{0\}".format(pathlib.Path(r"{toxworkdir}") / "docs_out" / "index.html"))'

# Binder
[testenv:binder]
description = ensure /binder/*ipynb are runnable
deps =
    -r binder/requirements.txt
commands = python -c "import glob; import papermill as pm; [pm.execute_notebook(input, '{toxworkdir}/out.ipynb', parameters=\{'binder_dir':'binder'\}) for input in glob.glob('binder/**/*.ipynb')]"

# Distro
[testenv:dist]
skip_install = true
commands =
    python setup.py sdist --dist-dir={distdir} bdist_wheel --dist-dir={distdir}
    /bin/bash -c 'python -m pip install -U --force-reinstall {distdir}/papermill*.tar.gz'
    /bin/bash -c 'python -m pip install -U --force-reinstall {distdir}/papermill*.whl'

[testenv]
# disable Python's hash randomization for tests that stringify dicts, etc
setenv =
    PYTHONHASHSEED = 0
    AWS_ACCESS_KEY_ID=foobar_key
    AWS_SECRET_ACCESS_KEY=foobar_secret
passenv = *
basepython =
    py38: python3.8
    py39: python3.9
    py310: python3.10
    py311: python3.11
    py312: python3.12
    manifest: python3.11
    dist: python3.12
    docs: python3.11
    binder: python3.11
deps = .[dev]
# Have to use /bin/bash or the `*` will cause that argument to get quoted by the tox command line...
allowlist_externals = /bin/bash
# Python 3.12 breaks default pip/setuptools versions ... force an upgrade of these before anything else
install_command = /bin/bash ./tox_py_installer.sh {opts} {packages}
commands = pytest -v --maxfail=2 --cov=papermill -W always {posargs}
